package com.open.web.rest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


/**
 * @author: codex
 * @Date: 2024/6/9 下午10:53
 * @Version: V1.0
 * @description: desc:
 */

@Tag(name = "文件上传下载")
@RequestMapping("/file")
public class FileController {

    private String filePath;


    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    @ResponseBody
    public String upload(@RequestParam("file") MultipartFile file) throws IOException {
        var originalFilename = file.getOriginalFilename();
        var path = filePath + File.separator + originalFilename;
        file.transferTo(new File(path));
        // 4C 8G 500G
        return "upload";
    }

    @Operation(summary = "文件下载")
    @GetMapping("/download/{fileName}")
    @ResponseBody
    public String download(@PathVariable("fileName") String fileName) {
        return "download";
    }
}
